package com.raos.example.config;

import dev.langchain4j.community.model.dashscope.QwenChatModel;
import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Condition;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject;

/**
 * 阿里百炼大模型平台配置属性
 *
 * @author raos
 * @date 2025-04-04
 */
@Configuration
public class DashscopeConfig {

    /*** 阿里百炼大模型平台属性配置前缀 */
    public static final String PREFIX = "langchain4j.community.dashscope";

    /*** 阿里百炼大模型平台-聊天模型属性配置前缀 */
    public static final String PREFIX_CHAT = "langchain4j.community.dashscope.chatModel";


    /**
     * 创建QwenChatModel对象
     */
    @Bean(name = "qwenChatModel")
    @Condition(onProperty = "${" + PREFIX_CHAT + ".enabled} = true")
    public QwenChatModel qwenChatModel(@Inject ChatModelProperties chatModelProperties) {
        return QwenChatModel.builder()
                .baseUrl(chatModelProperties.getBaseUrl())
                .apiKey(chatModelProperties.getApiKey())
                .modelName(chatModelProperties.getModelName())
                .temperature(chatModelProperties.getTemperature())
                .topP(chatModelProperties.getTopP())
                .topK(chatModelProperties.getTopK())
                .enableSearch(chatModelProperties.getEnableSearch())
                .seed(chatModelProperties.getSeed())
                .repetitionPenalty(chatModelProperties.getRepetitionPenalty())
                .temperature(chatModelProperties.getTemperature())
                .stops(chatModelProperties.getStops())
                .maxTokens(chatModelProperties.getMaxTokens())
                .build();
    }

}
